package com.example.toy.core.lock;

import com.example.toy.core.locker.ToyLock;
import com.example.toy.core.locker.ToyLockAbstractFactory;
import com.example.toy.core.table.TableIdentifier;
import com.example.toy.core.utils.ToyPathDefine;
import com.example.toy.core.version.ToyVersion;
import org.apache.hadoop.fs.Path;

/**
 * FsOfflineLockFactory
 *
 * @author shenbing
 * @date 2021/12/22
 */
public class FsOfflineLockFactory extends ToyLockAbstractFactory {

  public FsOfflineLockFactory() {}

  @Override
  public ToyLock buildTableLock(TableIdentifier tableIdentifier, Path basePath) {
    return new FileLock(ToyPathDefine.getTableLockPath(basePath));
  }

  @Override
  public ToyLock buildPartitionLock(
      TableIdentifier tableIdentifier, String partitionKey, Path partitionPath) {
    Path partitionLockPath = ToyPathDefine.getPartitionLockPath(partitionPath);
    return new FileLock(partitionLockPath);
  }

  @Override
  public ToyLock buildVersionLock(TableIdentifier tableIdentifier, ToyVersion version) {
    return null;
  }
}
